package com.jd.dlc.limit.dynamic;

import com.jd.dlc.domain.LimiterRule;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @program: dlc
 * @ClassName DlcLimiterRuleFactory
 * @description: throttling rule factory
 * @author: sizegang
 * @create: 2022-05-11
 **/
public class DlcLimiterRuleFactory {

    public volatile static Map<String, LimiterRule> limiterRuleMap = new ConcurrentHashMap();
    public volatile static boolean limitEnable = true;


    /**
     * Create or update throttling rules
     *
     * @param namespace
     * @param limiterRule
     */
    public static LimiterRule createUpdate(String namespace, LimiterRule limiterRule) {
        limiterRuleMap.put(namespace, limiterRule);
        return limiterRule;
    }

    /**
     * get configuration
     *
     * @param namespace
     */
    public static LimiterRule getConfig(String namespace) {
        return limiterRuleMap.get(namespace);
    }
}
